﻿layui.config({
    version: true,
    base: '/Plugin/'
}).extend({ //设定模块别名
    md5: 'md5', //如果 mymod.js 是在根目录，也可以不用设定别名
    common: 'common' //相对于上述 base 目录的子目录
    }).use(['element', 'jquery', 'layer', 'table', 'form', 'layedit', 'common'], function () {
    var element = layui.element,
        layer = layui.layer,
        table = layui.table,
        form = layui.form,
        common = layui.common,
        layedit = layui.layedit,
        $ = layui.jquery,
        about = null;

    //必须在框架内使用
    common.noneIframe();

    $(function () {
        $.ajax({
            type: "post",
            url: "/Ashx/admin.ashx",
            data: { functionname: "jhy_site_query" },
            dataType: 'json',
            success: function (msg) {
                if (msg.error == 0) {
                    layer.msg("未初始数据");
                } else {
                    $("#logotext").val(msg[0].site_logotext);
                    $("#inputicon").val(msg[0].site_logoicon);
                    $("#notice").val(msg[0].site_notice);
                    $("#copyright").val(unescape(msg[0].site_copyright));
                    $("#about").val(unescape(msg[0].site_about));
                    about = layedit.build('about', {
                        height: 320 //设置编辑器高度
                    });
                }
            }
        });
    })







    //预览图标
    $("#btnpreview").click(function () {
        var css = $.trim($("#inputicon").val());
        if (css != "") {
            $("#preview").html("<i class='layui-icon " + css + "'></i>");
        } else {
            layer.msg("还没有内容");
        }
        return false;
    });

    //保存
    form.on('submit(btnsubmit)', function (data) {
        var data = data.field,
            site_logotext = data.logotext,
            site_logoicon = data.logoicon,
            site_notice = data.notice,
            site_copyright = escape(data.copyright),
            site_about = escape(layedit.getContent(about));

        $.ajax({
            type: "post",
            url: "/Ashx/admin.ashx",
            data: { functionname: "jhy_site_update", site_logotext: site_logotext, site_logoicon: site_logoicon, site_notice: site_notice, site_copyright: site_copyright, site_about: site_about },
            success: function (msg) {
                if (msg == 'true') {
                    layer.msg("成功");
                } else {
                    layer.msg("失败");
                }
            }
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

});  
